package com.algorithm.lesson_04;

import java.util.Stack;

import org.junit.Test;

public class LessonTest {

	@Test
	public void testSlidingWindowMaxArray() {
		int[] arr = { 4, 3, 5, 4, 3, 3, 6, 7 };
		int w = 3;
		SlidingWindowMaxArray.printArray(SlidingWindowMaxArray.getMaxWindow(arr, w));
		SlidingWindowMaxArray.printArray(SlidingWindowMaxArray.getMinWindow(arr, w));
	}

	@Test
	public void testExpressionCompute() {
		String exp = "48*((70-65)-43)+8*1";
		System.out.println(ExpressionCompute.getValue(exp));

		exp = "4*(6+78)+53-9/2+45*8";
		System.out.println(ExpressionCompute.getValue(exp));

		exp = "10-5*3";
		System.out.println(ExpressionCompute.getValue(exp));

		exp = "-3*4";
		System.out.println(ExpressionCompute.getValue(exp));

		exp = "3+1*4";
		System.out.println(ExpressionCompute.getValue(exp));
	}

	@Test
	public void testReverseStackByRecursive() {
		Stack<Integer> stack = new Stack<>();
		stack.push(1);
		stack.push(2);
		stack.push(3);
		stack.push(4);
		stack.push(5);
		ReverseStackByRecursive.reverse(stack);
		while (!stack.isEmpty()) {
			System.out.println(stack.pop());
		}
	}

	@Test
	public void testTwoQueuesImplStack() {
		TwoQueuesImplStack<String> stack = new TwoQueuesImplStack<String>();
		stack.push("1");
		stack.push("2");
		stack.push("3");
		System.out.println(stack.peek());
		System.out.println(stack.pop());
		System.out.println(stack.size());
		stack.push("4");
		System.out.println(stack.peek());
		System.out.println(stack.pop());
		System.out.println(stack.size());
		System.out.println(stack.peek());
		System.out.println(stack.pop());
		System.out.println(stack.size());
	}

	@Test
	public void testTwoStacksImplQueue() {
		TwoStacksImplQueue queue = new TwoStacksImplQueue();
		queue.add(1);
		queue.add(2);
		queue.add(3);
		System.out.println(queue.peek());
		System.out.println(queue.poll());
		System.out.println(queue.peek());
		System.out.println(queue.poll());
		System.out.println(queue.peek());
		System.out.println(queue.poll());
	}

	@Test
	public void testGetMinStackImpl2() {
		GetMinStack<Integer> stack2 = new GetMinStackImpl2();
		stack2.push(3);
		System.out.println(stack2.getMin());
		stack2.push(4);
		System.out.println(stack2.getMin());
		stack2.push(1);
		System.out.println(stack2.getMin());
		System.out.println(stack2.pop());
		System.out.println(stack2.getMin());
	}

	@Test
	public void testGetMinStackImpl1() {
		GetMinStack<Integer> stack1 = new GetMinStackImpl1();
		stack1.push(3);
		System.out.println(stack1.getMin());
		stack1.push(4);
		System.out.println(stack1.getMin());
		stack1.push(1);
		System.out.println(stack1.getMin());
		System.out.println(stack1.pop());
		System.out.println(stack1.getMin());
	}
}
